{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = np.random.random(12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.57503742, 0.69472054, 0.05324036, 0.06994604, 0.64684792,\n",
       "       0.55928846, 0.27427374, 0.34435711, 0.35225955, 0.21361757,\n",
       "       0.04307336, 0.72215898])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "A = a.reshape(3, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.57503742, 0.69472054, 0.05324036, 0.06994604],\n",
       "       [0.64684792, 0.55928846, 0.27427374, 0.34435711],\n",
       "       [0.35225955, 0.21361757, 0.04307336, 0.72215898]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.57503742, 0.69472054, 0.05324036, 0.06994604, 0.64684792,\n",
       "       0.55928846, 0.27427374, 0.34435711, 0.35225955, 0.21361757,\n",
       "       0.04307336, 0.72215898])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 直接改变a的形状\n",
    "a.shape = (3, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.57503742, 0.69472054, 0.05324036, 0.06994604],\n",
       "       [0.64684792, 0.55928846, 0.27427374, 0.34435711],\n",
       "       [0.35225955, 0.21361757, 0.04307336, 0.72215898]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.57503742, 0.69472054, 0.05324036, 0.06994604, 0.64684792,\n",
       "       0.55928846, 0.27427374, 0.34435711, 0.35225955, 0.21361757,\n",
       "       0.04307336, 0.72215898])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.ravel()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "a.shape = (12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.57503742, 0.69472054, 0.05324036, 0.06994604, 0.64684792,\n",
       "       0.55928846, 0.27427374, 0.34435711, 0.35225955, 0.21361757,\n",
       "       0.04307336, 0.72215898])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.57503742, 0.64684792, 0.35225955],\n",
       "       [0.69472054, 0.55928846, 0.21361757],\n",
       "       [0.05324036, 0.27427374, 0.04307336],\n",
       "       [0.06994604, 0.34435711, 0.72215898]])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 矩形转置\n",
    "A.transpose()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
